export default class PreLoad {
    static loadImage(src: string) {
        return new Promise((resolve, reject) => {
            let img = new Image();
            img.onload = function () {//加载时执行resolve函数
                resolve(img);
            }
            img.onerror = function () {
                reject(src);
            }
            img.src = src;
        })
    }
    static async preload(srcArr: Array<string>) {
        let arr: any[] = [];
        for (let i = 0; i < srcArr.length; i++) {
            let item = srcArr[i];
            await this.loadImage(`../images/homebg_${item}.jpg`).then(img => {
                arr.push(img)
            })
        }
        return arr;
    }
}